package com.song.module.app.controller;


import com.song.common.result.R;
import com.song.framework.annotation.RateLimiter;
import com.song.module.admin.entity.ApContent;
import com.song.module.admin.request.ApContentRequest;
import com.song.module.admin.service.IApContentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 动态控制层
 *
 * @author song
 * @date 2024-03-13
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "动态接口管理", tags = "动态接口管理")
@RequestMapping("/app/apContent")
public class AppContentController {

    private final IApContentService iApContentService;


    /**
     * 动态列表
     */
    @ApiOperation(value = "动态列表")
    @PostMapping("/list")
    public R<List<ApContent>> pageList(@RequestBody ApContentRequest apContentRequest) {
        return R.success(iApContentService.list(apContentRequest));
    }


    /**
     * 发布动态
     */
    @RateLimiter
    @ApiOperation(value = "发布动态")
    @PostMapping("/publish")
    public R<Void> publish(@RequestBody ApContentRequest apContentRequest) {
        iApContentService.publish(apContentRequest);
        return R.success();
    }

    /**
     * 获取动态详细信息
     */
    @ApiOperation(value = "获取动态详细信息")
    @GetMapping(value = "/detail")
    public R<ApContent> detail(String id) {
        return R.success(iApContentService.getById(id));
    }


    /**
     * 获取动态详细信息
     */
    @ApiOperation(value = "获取动态详细信息")
    @PostMapping(value = "/like")
    public R<String> add_like(@RequestBody ApContentRequest apContentRequest) {
        iApContentService.add_like(apContentRequest.getType(), apContentRequest.getId());
        return R.success("success");
    }
}
